package com.leetcode.August;

import javax.swing.tree.TreeNode;

/**
 * @Description: 验证二叉搜索树
 * @Author: Mr.Fxy
 * @CreateTime: 2024-07-31 09:25
 */
public class vaildTree {
    public boolean isValidBST(TreeNode root) {
        return isValidBST(root, Long.MIN_VALUE, Long.MAX_VALUE);
    }

    private boolean isValidBST(TreeNode node, long min, long max) {
        if (node == null) {
            return true;
        }
        if (node.val <= min || node.val >= max) {
            return false;
        }
        return isValidBST(node.left, min, node.val) && isValidBST(node.right, node.val, max);
    }
}
